﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lucene.Net.Index;
using Lucene.Net.Analysis.China;
using Lucene.Net.Store;
using Lucene.Net.Documents;
using System.IO;
using System.Text.RegularExpressions;

namespace ASPNETX_SE
{
    public class IndexerD
    {
        private IndexWriter writer;

        public IndexerD()
        {
            string path=System.Environment.CurrentDirectory + "/IndexedFiles/";
            
            FSDirectory dir = FSDirectory.GetDirectory(path,true);
            
            writer = new IndexWriter(dir, new ChineseAnalyzer(), true);
        }

        public void AddRecord(string url)
        {
            Document doc = new Document();

            //string content = HTMLHelper.GetURLContent(url);

            //Field fldPath = new Field("Path", url, Field.Store.YES, Field.Index.TOKENIZED);
            //Field fldContent = new Field("Content", HTMLHelper.ParseHtml(content), Field.Store.YES, Field.Index.TOKENIZED);
            //Field fldTitle = new Field("Title", HTMLHelper.GetTitle(content), Field.Store.YES, Field.Index.TOKENIZED);

            //doc.Add(fldPath);
            //doc.Add(fldContent);
            //doc.Add(fldTitle);
            
            writer.AddDocument(doc);
        }

        public void Index()
        {
            writer.Optimize();
            writer.Close();
        }
    }
}
